import JSEncrypt from 'jsencrypt-rsa';
/**
 * JSEncrypt ras 加密
 */
export default class Encrypt {
  private encryptInstance;
  // 公钥
  private publicKey = decodeURI(
    'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnDgB3vqqvZ1xEL9Eyvpay8GSZM8blRyzu2bRCJVzRuKB1Hkg1p6yCBtvKmwz4VkWjq23cmkPUsMFNgCClbtw30PSe+91cTPuIWTk1UC11PWf3xubl3jUlgtN6ugKUi+OaG7Z5IFacPa6XKaSoHjh9pX+C7UYGTnBGIX10AESqowIDAQAB',
  );
  constructor() {
    if (!this.encryptInstance) {
      this.encryptInstance = new JSEncrypt(); // #实例化加密对象
    }
  }
  /**
   * @description: 加密
   * @param {String} val  需要加密的字符串
   * @return {*}
   */
  public encryptLong2(val) {
    // #设置加密公钥
    this.encryptInstance.setPublicKey(this.publicKey);
    return this.encryptInstance.encryptLong2(val);
  }
  /**
   * @description: 销毁
   * @param {*}
   * @return {*}
   */
  public destroyed() {
    this.encryptInstance = null;
  }
}
